package web;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.DBCon;

/**
 * Servlet implementation class AddTeaName
 */
@WebServlet({ "/AddTeaName", "/Manager/AddTea" })
public class AddTeaName extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//在教师统计表内插入姓名
				String sql;
				String[][] UserNum=new String[50][2]; //50个教师账号
				String sql_findDepName;
				
				ResultSet rs;

				try {
					//teacher表的数据插入操作
					sql_findDepName="Select TeaId,TeaName From teacher";
					rs=new DBCon().find(sql_findDepName);
					int i=0;
					while(rs.next()) {
						UserNum[i][0]=rs.getString("TeaId");
						UserNum[i][1]=rs.getString("TeaName");
						i++;
					}
					//获取到了全部教师账号和姓名
					//写循环
					//生成User表测试集		
					for(i=0;i<50;i++) {
						String Num=UserNum[i][0];
						String Name=UserNum[i][1];
							sql="update teastatistics set TeaName='"+Name+"' where TeaId='"+Num+"'";
							int ret;
							ret=new DBCon().query(sql);
							System.out.println("ret="+ret);
						
					}
				}catch (ClassNotFoundException | SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
